<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>绑定函数-快捷调用</title>
        <style>
            .notify{
                box-sizing:border-box;
                padding: 10px;
                border-left: 5px solid #e66465;
                background-color: #ffe7e8;
                margin-bottom: 20px;
            }
            .notify strong{
                font-weight: 700;
            }
        </style>
    </head>
    <body>
        <h1>绑定函数-快捷调用</h1>
        <p>来源:<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/bind">https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/bind</a></p>
        <script>
            var slice = Array.prototype.slice;

            // ...
            // same as "slice" in the previous example
            var unboundSlice = Array.prototype.slice;
            var slice1 = Function.prototype.apply.bind(unboundSlice);

            // ...

            
            function add() {
                // var arr = slice.apply(arguments),
                var arr = slice1(arguments);
                    sum = 0;
                for(var i=0,len=arr.length;i<len;i++){
                    sum += arr[i];
                }
                return sum;
            }
            console.log('slice1='+add(3,6,9));
        </script>
    </body>
</html>